//
//  AYuStatus.swift
//  SHWeibo3
//
//  Created by 余伟康 on 16/7/23.
//  Copyright © 2016年 wangce. All rights reserved.
//
//  model 字典转模型

import UIKit

class AYuStatus: NSObject {

    // MARK: - 模型属性
    // 创建时间
    var created_at:String?
    // 微博id
    var id :Int64 = 0
    // 微博信息内容
    var text: String?
    /// 微博来源
    var source:String?
    // 用户数据
    var user: AYuUser?
    // 转发微博
    var retweeted_status:AYuStatus?
    // 配图
    var pic_urls:[AYuPictureInfo]?
    
    
    // kvc构造函数
    init(dict:[String:AnyObject]) {
        super.init()

        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        // 如果key ==user
        if key == "user" {
            guard let v = value as? [String:AnyObject] else{
                return
            }
            // 给其赋值
            user = AYuUser(dict: v)
        }else if key == "retweeted_status" {
            guard let v = value as? [String:AnyObject] else{
                return
            }
            // 给其赋值
            retweeted_status = AYuStatus(dict:v)
            
        }else if key == "pic_urls" {
            guard let v = value as? [[String:AnyObject]] else{
                return
            }
            
            var tempArray:[AYuPictureInfo] = [AYuPictureInfo]()
            for dic in v{
                let pic = AYuPictureInfo(dict:dic)
                tempArray.append(pic)
            }
            
            // 给其赋值
            pic_urls = tempArray
            
            
        }else{
             //还需要系统帮我们字典转模型
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
}
